<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../style/css/style.css" rel="stylesheet" type="text/css"/>
    <script src="../../style/js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="../../style/js/ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript">

        var imgSrc = null;

        function fileUpload() {
            var adPosition = $("input[name='adPosition']:checked").val();
            var url = $("#urlId").val();

            $.ajaxFileUpload({
                    url: '../../ad/fileUpload', //用于文件上传的服务器端请求地址  调用后端接口(interface)
                    fileElementId: 'fileId', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    data: {
                        adPosition : adPosition,
                        url : url
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            imgSrc = data.data;
                            alert("添加成功");
                            location.replace("list.html");
                        }
                    }
                }
            )
        }


        function save() {
            $.post("../../ad/save", $("#formId").serialize(), function (res) {
                if (res == 200) {
                    alert("添加成功");
                } else {
                    alert("添加失败");
                }
            });
        }
    </script>
</head>

<body>
<form id="formId">
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <li>
                <label>广告位</label>
                <input type="radio" value="1" name="adPosition">广告位1
                <input type="radio" value="2" name="adPosition">广告位2
                <input type="radio" value="3" name="adPosition">广告位3
            </li>
            添加广告图
            <input type="file" name="fileName" accept=".jpg,.png,.gif" id="fileId">


            <br/>
            添加广告地址
            <input type="text" name="url" id="urlId" class="dfinput">

            <li>
                <input name="save" type="button" value="确认修改" class="dfinput" onclick="fileUpload()"/>
            </li>
        </ul>
    </div>
</form>
</body>

</html>
